package com.leyou.controller;

import com.leyou.service.GoodsHtmlService;
import com.leyou.service.GoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.Map;

@Controller
@RequestMapping("item")
public class GoodsController {

    @Autowired
    private GoodsService goodsService;

    @Autowired
    private GoodsHtmlService goodsHtmlService;

    /**
     * 跳转绕商品详情页
     */
    @GetMapping("{id}.html")
        public String toltePage(@PathVariable("id")Long id, Model model){
        Map<String, Object> map = goodsService.loadData(id);
        model.addAllAttributes(map);

        // 页面静态化
        goodsHtmlService.createHtml(id);

        return "item";
    }
}
